import React from 'react';
import { Route, Switch,Redirect } from "react-router-dom";
// import app from './App.module.css';
import './App.css';

// import { lazy } from 'react';
// import L from './L';
import Main from './Main/index'
import Login from './Login/index'
import {userContext} from './Context/userContext';
console.log('REACT_APP_PROJECT_NAME =',process.env.REACT_APP_PROJECT_NAME);
// const Header = lazy(() => import(`./Header/${process.env.REACT_APP_PROJECT_NAME}/index`))
// const Footer = lazy(() => import(`./Footer/${process.env.REACT_APP_PROJECT_NAME}/index`))


/**
 * 需要登录才能访问的组件
 */
function NeedLogin(props){
	// 在此验证是否已登录
	let user  = localStorage.getItem(process.env.REACT_APP_PROJECT_NAME+'_user');
	return (
		user ? <userContext.Provider value={JSON.parse(user)}><Main {...props}/></userContext.Provider> : <Redirect to="/login"/>
	)
}


function App() {
	return (
		<div className="App">
			<Switch>
				<Route path="/login" component={Login}></Route>
				<Route path="/" component={NeedLogin}></Route>
			</Switch>
		</div>
	);
}

export default App;
